package com.example.demo4.config;

import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author lxb
 */
@Configuration
public class FlowableConfig {

    @Primary
    @Bean(name = "processEngineOne")
    public ProcessEngine processEngineOne() {
        //获取ProcessEngineConfiguration对象
        ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
                //配置相关数据库的连接信息
                .setJdbcUrl("jdbc:mysql://localhost:3306/flowable17?serverTimezone=UTC&nullCatalogMeansCurrent=true")
                .setJdbcUsername("root")
                .setJdbcPassword("root")
                .setJdbcDriver("com.mysql.cj.jdbc.Driver")
                //如果书库中的表结构不存在就新建
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)

                .setActivityFontName("宋体")
                .setLabelFontName("宋体")
                .setAnnotationFontName("宋体");

        ProcessEngine processEngine = cfg.buildProcessEngine();
        return processEngine;
    }

    @Bean(name = "processEngineTwo")
    public ProcessEngine processEngineTwo() {
        ProcessEngineConfiguration configuration = ProcessEngineConfiguration
                .createProcessEngineConfigurationFromResource("flowable.cfg.xml");
        ProcessEngine processEngine = configuration.buildProcessEngine();
        return processEngine;
    }
}

